{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Damage mark"

// By ArtemQa146

//         txd
0390: load_txd_dictionary 'rsqa'
038F: load_texture "blood" as 1
0E3C: get_texture_from_sprite 1 store_to 31@
0391: release_textures

const
    Sprite_texture = 31@
    Alpha_texture = 8@
    Size_texture = 14@
    Damager = 0@
    Max_X = 500.0
    Max_X_2 = 150.0
    Max_Y = 400.0
    Max_Y_2 = 20.0
    R_ini = 29@
    G_ini = 28@
    B_ini = 27@
    Time_ini = 26@
    Alpha_ini = 25@
    Minus_Alpha_ini = 24@
    Size_ini = 23@
    Plus_size_ini = 22@
end

0AF0: R_ini = read_int_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "R"
0AF0: G_ini = read_int_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "G"
0AF0: B_ini = read_int_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "B"

0AF0: Time_ini = read_int_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "Time"

0AF0: Alpha_ini = read_int_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "Current Alpha"
0AF0: Minus_Alpha_ini = read_int_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "Minus alpha"

0AF2: Size_ini = read_float_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "Current Size"
0AF2: Plus_size_ini = read_float_from_ini_file "cleo\Damage mark.ini" section "Visual Settings" key "Plus Size"

while true
wait 0
    if
        player.Defined(0)
    then
        30@ = 0
        while 0EA7: get_any_char_no_save_recursive 30@ progress_to 30@ char_to Damager
        if and
            803B:   not $PLAYER_ACTOR == Damager  // (int)
            051A:   actor $PLAYER_ACTOR damaged_by_actor Damager
        then
            timera = 0
            0085: Alpha_texture = Alpha_ini // (int)
            0087: Size_texture = Size_ini // (float)
            054E: clear_actor $PLAYER_ACTOR damage

            //  .     1   1 
            repeat
            wait 0
            if
                056D:   actor Damager defined
            then
                if or
                    001D:   timera > Time_ini  // (int)
                    Alpha_texture < 1
                then
                    break
                end
                04C4: store_coords_to 1@ 2@ 3@ from_actor Damager with_offset 0.0 0.0 0.0
                if
                    convert_3d_to_screen_2d 1@ 2@ 3@ checkNearClip 0 checkFarClip 1 store_2d_to 4@ 5@ size_to 1@ 1@
                then
                    //    c
                    if 4@ > Max_X
                    then 4@ = Max_X
                    end
                    if 4@ < Max_X_2
                    then 4@ = Max_X_2
                    end
            
                    //    c
                    if 5@ > Max_Y
                    then 5@ = Max_Y
                    end
                    if 5@ < Max_Y_2
                    then 5@ = Max_Y_2
                    end

                    //    
                    0087: 9@ = 4@ // (float)
                    0087: 10@ = 5@ // (float)
            
                    //        , .
                    if and
                        5@ > 50.0
                        5@ < 300.0
                    then
                        if and
                            4@ > 200.0
                            4@ < 450.0
                        then
                            10@ = 50.0
                        end
                    end
                    //        , .
                    if and
                        5@ >= 300.0
                        5@ < 390.0
                    then
                        if and
                            4@ > 200.0
                            4@ < 450.0
                        then
                            10@ = 390.0
                            //6@ += 180.0
                        end
                    end

                    0087: 5@ = 10@ //   Y
            
                    //        , .
                    if and
                        4@ > 200.0
                        4@ < 324.0
                    then
                        if and
                            5@ > 50.0
                            5@ < 390.0
                        then
                            9@ = 200.0
                        end
                    end
                    //        , .
                    if and
                        4@ >= 324.0
                        4@ < 450.0
                    then
                        if and
                            5@ > 50.0
                            5@ < 390.0
                        then
                            9@ = 450.0
                        end
                    end
            
                    0087: 4@ = 9@ // //   X
                    
                    //  . -80,0   80,0 
                    6@ = -80.0
                    0087: 7@ = 4@ // (float)
                    7@ /= 4.05 // 648.0 / 160.0 = 4.05
                    005B: 6@ += 7@  // (float)
                    0087: 7@ = 5@ // (float)
                    7@ /= 12.8
                    if 4@ > 320.0
                    then 005B: 6@ += 7@  // (float)
                    else 0063: 6@ -= 7@  // (float)
                    end
            
                    //    
                    0EB2: get_offset_from_camera_in_world_coords 0.0 -150.0 0.0 store_to 11@ 12@ 13@
                    if
                        0EEA: locate_char_distance_to_coordinates Damager pos 11@ 12@ 13@ radius 151.0
                    then
                        5@ = 390.0 //   
                        6@ += 180.0 //  
                        
                        //  
                        if
                            4@ > 324.0
                        then
                            0087: 7@ = 4@ // (float)
                            7@ -= 324.0
                            4@ = 324.0
                            0063: 4@ -= 7@  // (float)
                        else
                            0087: 7@ = 4@ // (float)
                            4@ = 324.0
                            0063: 4@ -= 7@  // (float)
                            7@ = 324.0
                            005B: 4@ += 7@  // (float)
                        end
                    end
                    
                    gosub @Draw // 
                    
                end
            else //   
                break
            end
            until not player.Defined(0)
            end
        end
    end
end

:Draw
0E1E: draw_texture_plus Sprite_texture event 1 pos 4@ 5@ size Size_texture Size_texture angle 6@ 0.0 1 0 0 rgba R_ini G_ini B_ini Alpha_texture
0062: Alpha_texture -= Minus_Alpha_ini  // (int)
005B: Size_texture += Plus_size_ini  // (float)
return